package commands;

import IA.InformationAggregator;
import java.util.*;
public class CmdGetAveragePrepTime extends Command {
    public CmdGetAveragePrepTime(InformationAggregator IA) {
        super(IA);
    }
    
    @Override
    
    //return the average prep time for the last 100 cooked items
    public String execute() {
        int sum = 0; int numTimes = 0;
        for(Iterator<Integer> itr = ia.getKitchenQueue().getPastPrepTimeIterator(); itr.hasNext() && numTimes <= 100; ) {
            sum += itr.next();
            numTimes++;
        }
        if(numTimes == 0) return "0.00";
        else {
            java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
            double d = (double)sum/numTimes;
            nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2);
            return nf.format(d);
        }
    }
}